package diaosidadui.homework;

import java.util.Random;

public class Test12 {
    /*
    一个大V直播抽奖，奖品是现金红包，
    分别有{2,588,888,1000,10000}五个奖金。
    请使用代码模拟抽奖，打印出每个奖项，
    奖项的出现顺序要随机且不重复。打印效果如下：（随机顺序，不一定是下面的顺序）
     */
    public static void main(String[] args) {
        int[] money = {2, 588, 888, 1000, 10000,999999,1000000};

        int[] num = ranArr(money);

/*        for (int i = 0; i < num.length; i++) {
            System.out.print(num[i]+" ");
        }*/



        for (int i = 0; i < money.length; i++) {
            System.out.println(money[num[i]-1]);
        }

    }


    //生成一个元素随机且不重复的自然数数组,元素最小从1开始
    public static int[]  ranArr(int[] arr) {
        int[] num = new int[arr.length];
        Random r = new Random();

        for (int j = 0; j < arr.length; j++) {
            int ran = r.nextInt(arr.length) + 1;
            int index = -1;
            for (int i = 0; i <= j; i++) {
                //arr[i]
                if (num[i] == ran) {
                    index = 0;
                    break;
                }
            }
            if (index ==-1) {
                num[j] = ran;
            }else{
                j--;
            }
        }
        return num;


    }

}
